package com.ruoyi.vote.admin.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.vote.admin.domain.VoteActivity;
import com.ruoyi.vote.admin.service.IVoteLikeService;
import com.ruoyi.vote.common.strategy.ActivityContext;
import com.ruoyi.vote.common.strategy.UserLickCheck;
import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.vote.admin.domain.vo.VoteLikeVo;
import com.ruoyi.vote.admin.domain.bo.VoteLikeBo;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投票信息
 *
 * @author 筑巢
 * @date 2023-07-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/vote/like")
public class VoteLikeController extends BaseController {

    private final IVoteLikeService iVoteLikeService;

    /**
     * 投票信息列表
     */
    @SaCheckPermission("vote:like:list")
    @GetMapping("/list")
    public TableDataInfo<VoteLikeVo> list(VoteLikeBo bo, PageQuery pageQuery) {
        pageQuery.setOrderByColumn("create_time");
        pageQuery.setIsAsc("desc");
        return iVoteLikeService.queryPageList(bo, pageQuery);
    }

    /**
     * 投票详情
     *
     * @param id 主键
     */
    @SaCheckPermission("vote:like:query")
    @GetMapping("/{id}")
    public R<VoteLikeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iVoteLikeService.queryById(id));
    }

    /**
     * 选手投票
     */
    @Log(title = "投票", businessType = BusinessType.INSERT)
    @GetMapping("/add/{eventId}/{contestantId}")
    public R<Void> add(@PathVariable @NotNull(message = "活动不能为空") String eventId,@PathVariable @NotNull(message = "选手不能为空") String contestantId) {
        return toAjax(iVoteLikeService.likeUserVoting(String.valueOf(LoginHelper.getUserId()),eventId,contestantId));
    }

}
